package com.ukao.pad.dialog;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ukao.pad.R;
import com.ukao.pad.adapter.ClothesOperateStatusAdapter;
import com.ukao.pad.base.BaseDialogFragment;
import com.ukao.pad.bean.ClothesOperateStatusBean;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 *
 * 查看衣物操作状态的Fragment
 */
public class ClothesOperateStatusDialogFragment extends BaseDialogFragment {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    // TODO: Rename and change types of parameters
    private String clothesName;
    private String clothesCode;
    private  ArrayList<ClothesOperateStatusBean> arrayList;
    private Unbinder unbinder;
   @BindView(R.id.tv_clothes_name)
    TextView tvClothesName;
   @BindView(R.id.tv_code_no)
   TextView tvBarCode;
   @BindView(R.id.rv_pass_status)
    RecyclerView  recyclerView;
   private ClothesOperateStatusAdapter  cosa;


    public ClothesOperateStatusDialogFragment() {
    }

    public static ClothesOperateStatusDialogFragment newInstance(ArrayList<ClothesOperateStatusBean> List, String clothesName, String clothesCode) {
        ClothesOperateStatusDialogFragment fragment = new ClothesOperateStatusDialogFragment();
        Bundle args = new Bundle();
        args.putParcelableArrayList("listData",List);
        args.putString(ARG_PARAM1,clothesName);
        args.putString(ARG_PARAM2, clothesCode);
        fragment.setArguments(args);
        return fragment;
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            arrayList=getArguments().getParcelableArrayList("listData");
            clothesName = getArguments().getString(ARG_PARAM1,"");
            clothesCode = getArguments().getString(ARG_PARAM2,"");
        }
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_clothes_operate_status, container, false);
        unbinder=    ButterKnife.bind(this,view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        getDialog().setCanceledOnTouchOutside(false);
        initView();
    }

    @Override
    protected void initView() {
        tvClothesName.setText(clothesName);
        tvBarCode.setText(clothesCode);
        //设置RecyclerView适配器
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.setHasFixedSize(true);
        cosa=new ClothesOperateStatusAdapter(getActivity(),arrayList);
        recyclerView.setAdapter(cosa);
    }

    @OnClick({R.id.red_img_close_btn})
    public void onViewClicked(View view) {
          switch (view.getId()){
              case R.id.red_img_close_btn:
                  dismiss();
                  break;
          }
    }

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Uri uri) {

    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }
}
